package com.ossjk.oa.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ossjk.core.util.CommonUtil;
import com.ossjk.oa.system.entity.PostPermission;
import com.ossjk.oa.system.mapper.PostPermissionMapper;
import com.ossjk.oa.system.service.IPostPermissionService;

/**
 * <p>
 * 岗位权限表 服务实现类
 * </p>
 *
 * @author chair
 * @since 2019-01-26
 */
@Service
public class PostPermissionServiceImpl extends ServiceImpl<PostPermissionMapper, PostPermission> implements IPostPermissionService {

	@Override
	public boolean updatePermission(String pid, String[] perid) {

		// 删除所有角色权限
		Wrapper wrapper = Condition.create().eq("pid", pid);
		this.baseMapper.delete(wrapper);

		if (!CommonUtil.isBlank(perid)) {
			List<PostPermission> postPermissions = new ArrayList();
			for (String peridStr : perid) {
				PostPermission postPermission = new PostPermission();
				postPermission.setPid(pid);
				postPermission.setPerid(peridStr);
				// rolePermissionService.insert(rolePermission);
				postPermissions.add(postPermission);
			}
			return this.insertBatch(postPermissions);
		} else {
			return true;
		}
	}

	@Override
	public List<String> selectPeridByPid(String pid) {
		return this.baseMapper.selectPeridByPid(pid);
	}

}
